package com.WFinstitute.serviceImpl;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.WFinstitute.domain.ScholarArticle;
import com.WFinstitute.repository.ScholarArticleRepository;
import com.WFinstitute.service.ScholarArticleService;
import com.WFinstitute.util.Page;

/**
 * 
 * @author 匹夫
 * @date 2016-7-31 上午10:13:46
 * @function
 */
@Service
public class ScholarArticleServiceImpl implements ScholarArticleService{
	@Resource
	private ScholarArticleRepository  scholarArticleRepository;

	@Override
	public ScholarArticle addScholarArticle(ScholarArticle scholarArticle) {
		return scholarArticleRepository.save(scholarArticle);
	}

	@Override
	public Page<ScholarArticle> findScholarArticleList(Integer pageSize,
			Integer pageIndex, String name) {
		String jpql="select n from ScholarArticle n order by n.createtime desc";
		return scholarArticleRepository.getAllPage(jpql, null, pageSize, pageIndex);
	}

	@Override
	public Page<ScholarArticle> findScholarArticleListByReading(Integer pageSize,
			Integer pageIndex, String name) {
		String jpql="select n from ScholarArticle n order by n.readingcount desc";
		return scholarArticleRepository.getAllPage(jpql, null, pageSize, pageIndex);
	}
	
	@Override
	public long count() {
		return scholarArticleRepository.count();
	}

	@Override
	public ScholarArticle updateScholarArticle(ScholarArticle scholarArticle) {
		return (ScholarArticle)scholarArticleRepository.update(scholarArticle);
	}

	@Override
	public ScholarArticle findScholarArticleById(Integer id) {
		return scholarArticleRepository.findOne(id);
	}

	@Override
	public void deleteScholarArticleById(Integer id) {
		scholarArticleRepository.delete(id);
		
	}

	@Override
	public List<ScholarArticle> findScholarArticleList() {
		return scholarArticleRepository.findAll();
	}

	@Override
	public  List<ScholarArticle> findScholarArticleByScholarname(String scholarname) {
		return scholarArticleRepository.findScholarArticleByScholarname(scholarname);
	}


}
